//
//  LSYueZhimangerVC.m
//  LaSaCivilAffairsDepartment
//
//  Created by 姜晓延 on 2019/8/21.
//  Copyright © 2019 wpkj. All rights reserved.
//

#import "LSYueZhimangerVC.h"
#import "JSONUtils.h"
#import "YueZhiCell.h"
#import "YueZhiInfoVC.h"
#import "LSContactSelectViewController.h"
#import "LSContactSelectTableViewModel.h"
#define SelectViewWidth (147/3*2)
#define SelectViewHeight 100
//(275/3*2)
#define headerSearchViewHeight 103
#define CountPerPage 10
@interface LSYueZhimangerVC ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, assign) BOOL nwglXialaImageViewIsShowing;
@property (nonatomic, strong) UIImageView *nwglXialaImageView;
@property (nonatomic, strong) UIView *backgroundAlphaView;
@property (nonatomic, strong) NSArray <NSDictionary *> *selectButtonsArray;
@property (nonatomic, strong) UITableView *yueZhiTableView;
@property (nonatomic, strong) NSMutableArray *dataArrayM;
@property (nonatomic, strong) UITextField *yueZhiName;
@property (nonatomic, strong) UITextField *yueZhiNum;
@property (nonatomic, assign) NSInteger tablePage;
@property (nonatomic, strong) UIButton *chooseBtn;
@property (nonatomic, strong) NSDictionary *selectDict;
@property (nonatomic, strong) NSDictionary *responseObject;
//阅知
@property (nonatomic, strong) UIView *yzView;
@property (nonatomic, strong) NSArray *chosenArray;
@end
static NSString *yueZhiTableViewCellID = @"yueZhiTableViewCellID";
@implementation LSYueZhimangerVC
- (UIView *)yzView{
    if (!_yzView) {
        _yzView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _yzView.backgroundColor =hexColorAlpha(000000, 0.5);
        _yzView.userInteractionEnabled = true;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yzViewTapped)];
        [_backgroundAlphaView addGestureRecognizer:tap];
    }
    
    return _yzView;
}
- (void)yzViewTapped{
    [self.yzView removeFromSuperview];
    for (LSContactSelectTableViewModel *model in self.chosenArray) {
        model.isSelected = false;
    }
    self.chosenArray = @[];
}
- (void)selectYueZhiPerson{
    
    //    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [self.tabBarController.view addSubview:self.yzView];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, (ScreenHeight-(20+30+10+50+10+30+10+10+10))/2.0, ScreenWidth, 20+30+10+50+10+30+10+10+10)];
    view.backgroundColor = hexColor(ffffff);
    [self.yzView addSubview:view];
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 60)];
    topView.backgroundColor = hexColor(ffffff);
    [view addSubview:topView];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, 100, 30)];
    label.textColor = hexColor(333333);
    label.text = @"阅知人选择";
    [topView addSubview:label];
    
    UIButton *chooseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    chooseBtn.frame = CGRectMake(ScreenWidth-20-60-20-60-10, 15, 60, 40);
    chooseBtn.backgroundColor = hexColor(EEEEEE);
    [chooseBtn setTitle:@"选择" forState:UIControlStateNormal];
    [chooseBtn setTitleColor:hexColor(333333) forState:UIControlStateNormal];
    [topView addSubview:chooseBtn];
    
    
    UIButton *clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    clearBtn.frame = CGRectMake(ScreenWidth-20-60,15, 60, 40);
    clearBtn.backgroundColor = hexColor(EEEEEE);
    [clearBtn setTitle:@"清空" forState:UIControlStateNormal];
    [clearBtn setTitleColor:hexColor(333333) forState:UIControlStateNormal];
    [topView addSubview:clearBtn];
    
    UILabel *personsLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(topView.frame)+10, ScreenWidth-20, 50)];
    personsLabel.clipsToBounds = YES;
    personsLabel.layer.cornerRadius = 5;
    personsLabel.layer.borderColor = hexColor(A6A6A6).CGColor;
    personsLabel.layer.borderWidth  = 1;
    personsLabel.textColor = hexColor(666666);
    personsLabel.font = [UIFont systemFontOfSize:15];
    [view addSubview:personsLabel];
    personsLabel.tag = 800;
    
    CGFloat maxY = CGRectGetMaxY(personsLabel.frame)+10;
    
    UIButton *quxiaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quxiaoBtn.backgroundColor = topView.backgroundColor;
    quxiaoBtn.frame = CGRectMake(ScreenWidth-20-80, maxY, 80, 40);
    [quxiaoBtn setTitle:@"取消" forState:UIControlStateNormal];
    [quxiaoBtn setTitleColor:hexColor(333333) forState:UIControlStateNormal];
    [view addSubview:quxiaoBtn];
    quxiaoBtn.backgroundColor = hexColor(EEEEEE);
    
    UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    okBtn.backgroundColor = topView.backgroundColor;
    okBtn.frame = CGRectMake(ScreenWidth-20-80-20-80-10, maxY, 80, 40);
    [okBtn setTitle:@"确定" forState:UIControlStateNormal];
    [okBtn setTitleColor:hexColor(333333) forState:UIControlStateNormal];
    [view addSubview:okBtn];
    okBtn.backgroundColor = hexColor(EEEEEE);
    
    chooseBtn.clipsToBounds = YES;
    chooseBtn.layer.cornerRadius = 2;
    chooseBtn.layer.borderColor = hexColor(A6A6A6).CGColor;
    chooseBtn.layer.borderWidth  = 1;
    
    clearBtn.clipsToBounds = YES;
    clearBtn.layer.cornerRadius = 2;
    clearBtn.layer.borderColor = hexColor(A6A6A6).CGColor;
    clearBtn.layer.borderWidth  = 1;
    
    okBtn.clipsToBounds = YES;
    okBtn.layer.cornerRadius = 2;
    okBtn.layer.borderColor = hexColor(A6A6A6).CGColor;
    okBtn.layer.borderWidth  = 1;
    
    quxiaoBtn.clipsToBounds = YES;
    quxiaoBtn.layer.cornerRadius = 2;
    quxiaoBtn.layer.borderColor = hexColor(A6A6A6).CGColor;
    quxiaoBtn.layer.borderWidth  = 1;
    
    chooseBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    clearBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    okBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    quxiaoBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [quxiaoBtn addTarget:self action:@selector(yzViewTapped) forControlEvents:UIControlEventTouchUpInside];
    [chooseBtn addTarget:self action:@selector(chooseBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [okBtn addTarget:self action:@selector(okBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [clearBtn addTarget:self action:@selector(clearBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
- (void)chooseBtnClicked{
    for (LSContactSelectTableViewModel *model in self.chosenArray) {
        model.isSelected = false;
    }
    LSContactSelectViewController *contactSelectVC = [[LSContactSelectViewController alloc] initWithSelectedArray:self.chosenArray andCompleteHandler:^(NSArray * _Nonnull selectedArray) {
        self.chosenArray = selectedArray;
        if (selectedArray && selectedArray.count > 0) {
            NSMutableString *selectedStringM = [[NSMutableString alloc] initWithString:@""];
            for (LSContactSelectTableViewModel *model in selectedArray) {
                [selectedStringM appendFormat:@"%@,",model.realname];
            }
            UILabel *label = [self.yzView viewWithTag:800];
            label.text = selectedStringM.copy;
        }
    }];
    HEBaseNavController *nav = [[HEBaseNavController alloc] initWithRootViewController:contactSelectVC];
    [self presentViewController:nav animated:true completion:nil];
}
- (void)okBtnClicked{
    NSMutableString *selectedStringM = [[NSMutableString alloc] initWithString:@""];
    for (LSContactSelectTableViewModel *model in self.chosenArray) {
        [selectedStringM appendFormat:@"%@,",model.username];
    }
    NSDictionary *param = @{@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token],@"id":self.selectDict[@"id"],@"toUser":selectedStringM.copy};
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:yzReadAndknow param:param completionHandler:^(id responseObject, NSError *connectionError) {
        [hud hideAnimated:true];
        if (!connectionError) {
            self.chosenArray = @[];
            NSNumber *status = [responseObject objectForKey:@"status"];
            if (status.integerValue == 200) {
                [MBProgressHUD showTipMessageInWindow:[ValidateUtils validateNull:responseObject[@"message"]]];
                [self loadData];
            } else {
                [MBProgressHUD showTipMessageInWindow:[ValidateUtils validateNull:responseObject[@"message"]]];
            }
        } else {
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
    [self yzViewTapped];
}
- (void)clearBtnClicked{
    UILabel *label = [self.yzView viewWithTag:800];
    label.text = @"";
    for (LSContactSelectTableViewModel *model in self.chosenArray) {
        model.isSelected = false;
    }
    self.chosenArray = @[];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.tablePage = 1;
    [self loadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"阅知管理";
    UIBarButtonItem *moreBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"more"] style:UIBarButtonItemStylePlain target:self action:@selector(moreBarButtonItemClick)];
    self.navigationItem.rightBarButtonItem = moreBarButtonItem;
    self.nwglXialaImageViewIsShowing = false;
    [self setUpHeaderSearchView];
    [self.view addSubview:self.yueZhiTableView];
    WS
    self.yueZhiTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        weakSelf.tablePage = 1;
        [weakSelf loadData];
    }];
    self.yueZhiTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        weakSelf.tablePage++;
        [weakSelf loadData];
    }];
}
- (void)setUpHeaderSearchView {
    UIView *headerSearchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, headerSearchViewHeight)];
    headerSearchView.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:headerSearchView];
    UIView *headerViewBottomLineView = [[UIView alloc] initWithFrame:CGRectMake(0, headerSearchViewHeight-0.5, ScreenWidth, 0.5)];
    headerViewBottomLineView.backgroundColor = hexColor(CCCCCC);
    [headerSearchView addSubview:headerViewBottomLineView];
    
    // 拟文名
    UITextField *nameTF = [[UITextField alloc] initWithFrame:CGRectMake(15, 5+4, (ScreenWidth-30), 36)];
    self.yueZhiName = nameTF;
    nameTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
    nameTF.layer.borderColor = hexColor(dbdbdb).CGColor;
    nameTF.layer.borderWidth = 1;
    nameTF.returnKeyType = UIReturnKeySearch;
    nameTF.placeholder = @"请输入文件标题";
    nameTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 8, 1)];
    nameTF.leftViewMode = UITextFieldViewModeAlways;
    [headerSearchView addSubview:nameTF];
    
    
    UITextField *cardNumberTF = [[UITextField alloc] initWithFrame:CGRectMake(15, 54+4, ScreenWidth-30-55-15, 36)];
    self.yueZhiNum = cardNumberTF;
    cardNumberTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
    cardNumberTF.layer.borderColor = hexColor(dbdbdb).CGColor;
    cardNumberTF.layer.borderWidth = 1;
    cardNumberTF.returnKeyType = UIReturnKeySearch;
    cardNumberTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    cardNumberTF.placeholder = @"请输入原文编号";
    cardNumberTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 8, 1)];
    cardNumberTF.leftViewMode = UITextFieldViewModeAlways;
    [headerSearchView addSubview:cardNumberTF];
    
    UIButton *searchButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-15-55, 54+4, 55, 36)];
    searchButton.layer.cornerRadius = 4;
    searchButton.layer.masksToBounds = true;
    searchButton.backgroundColor = NAV_COLOR;
    [searchButton setTitle:@"搜索" forState:UIControlStateNormal];
    searchButton.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
    [searchButton addTarget:self action:@selector(loadData) forControlEvents:UIControlEventTouchUpInside];
    [headerSearchView addSubview:searchButton];
}
- (void)loadData {
    [self.view endEditing:YES];
    NSDictionary *param = @{@"fileTitle":[self.yueZhiName.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]],@"fileNum":[self.yueZhiNum.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]],@"rows":[NSString stringWithFormat:@"%d",CountPerPage],@"page":[NSString stringWithFormat:@"%ld",(long)self.tablePage]};
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:[NSString stringWithFormat:@"%@&token=%@",yzList,[UserInfoModel sharedInstance].token] param:param completionHandler:^(id responseObject, NSError *connectionError) {
        NSLog(@"参数：%@",param);
        [hud hideAnimated:true];
        if (!connectionError) {
            NSNumber *status = [responseObject objectForKey:@"status"];
            self.responseObject = [NSDictionary dictionaryWithDictionary:responseObject];
            if (self.tablePage == 1) {
                [self.yueZhiTableView.mj_header endRefreshing];
                [self.dataArrayM removeAllObjects];
            }
            if (status.integerValue == 200) {
                NSArray *dataArray = [responseObject objectForKey:@"data"];
                [self.dataArrayM addObjectsFromArray:dataArray];
                if (self.dataArrayM.count < self.tablePage*CountPerPage) {
                    [self.yueZhiTableView.mj_footer endRefreshingWithNoMoreData];
                }else{
                    [self.yueZhiTableView.mj_footer endRefreshing];
                }
                [self.yueZhiTableView reloadData];
            } else {
                [self.yueZhiTableView.mj_footer endRefreshingWithNoMoreData];
                [MBProgressHUD showTipMessageInWindow:responseObject[@"message"]];
            }
        } else {
            if (self.tablePage == 1) {
                [self.yueZhiTableView.mj_header endRefreshing];
            }else{
                [self.yueZhiTableView.mj_footer endRefreshingWithNoMoreData];
            }
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
}


- (void)moreBarButtonItemClick {
    if (self.nwglXialaImageViewIsShowing) {
        [self.nwglXialaImageView removeFromSuperview];
        [self.backgroundAlphaView removeFromSuperview];
        self.nwglXialaImageViewIsShowing = false;
    } else {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        [window addSubview:self.backgroundAlphaView];
        [window addSubview:self.nwglXialaImageView];
        self.nwglXialaImageViewIsShowing = true;
    }
}

- (UIImageView *)nwglXialaImageView {
    if (!_nwglXialaImageView) {
        NSInteger cout = 3;
        if ([[ValidateUtils validateNull:self.responseObject[@"isCode"]] isEqualToString:@"0"]) {
            cout = 3;
        }else{
            cout = 4;
        }
        _nwglXialaImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth-1-SelectViewWidth, SafeAreaTopHeight-15, SelectViewWidth, 10+30*cout)];
        _nwglXialaImageView.image = [UIImage imageNamed:@"nwgl_xiala"];
        _nwglXialaImageView.userInteractionEnabled = true;
        
        for (int i = 0; i < cout; i++) {
            UIButton *button  = [[UIButton alloc] initWithFrame:CGRectMake(0, 5+(10+30*cout-10)/cout*i, SelectViewWidth, (10+30*cout-10)/cout)];
            [button setImage:[UIImage imageNamed:self.selectButtonsArray[i][@"image"]] forState:UIControlStateNormal];
            [button setTitle:self.selectButtonsArray[i][@"title"] forState:UIControlStateNormal];
            button.tag = 1000+i;
            [button setTitleColor:hexColor(333333) forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            [_nwglXialaImageView addSubview:button];
            [button addTarget:self action:@selector(nwglXiaLaBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    return _nwglXialaImageView;
}
#pragma mark 新增 编辑 催办 督办 归档 流程图 按钮点击
- (void)nwglXiaLaBtnClicked:(UIButton*)button{
    [self.nwglXialaImageView removeFromSuperview];
    [self.backgroundAlphaView removeFromSuperview];
    self.nwglXialaImageViewIsShowing = false;
    switch (button.tag) {
        case 1000:
        {
            //新增
            YueZhiInfoVC *yvc = [[YueZhiInfoVC alloc]init];
            yvc.type = 2;
            [self.navigationController pushViewController:yvc animated:YES];
        }
            break;
        case 1001:
        {
            //编辑
            if ([self.selectDict allKeys].count == 0) {
                [MBProgressHUD showWarnMessage:@"请选择编辑项目！"];
                return;
            }else{
                if ([self.selectDict[@"isFiling"] isEqualToString:@"1"]) {
                    [MBProgressHUD showWarnMessage:@"数据已归档，不可编辑！"];
                    //                    NZKAlertView *tipView = [[NZKAlertView alloc] initWithImageView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gdcg"]] title:@"数据已归档，不可操作" delegate:nil buttonTitle:@"我知道了"];
                    //                    [tipView show];
                    return;
                }else{
                    if (![[ValidateUtils validateNull:self.selectDict[@"toUserNum"]] isEqualToString:@"0"]) {
                        [MBProgressHUD showWarnMessage:@"数据已被阅知，不可编辑！"];
                        return;
                    }else{
                        YueZhiInfoVC *yvc = [[YueZhiInfoVC alloc]init];
                        yvc.type = 3;
                        yvc.dict = self.selectDict;
                        [self.navigationController pushViewController:yvc animated:YES];
                        
                    }
                    
                    
                }
                
            }
            
        }
            break;
            
            
            break;
        case 1002:
        {
            //阅知
            if ([self.selectDict allKeys].count == 0) {
                [MBProgressHUD showWarnMessage:@"请选择阅知项目！"];
                return;
            }else{
                if ([self.selectDict[@"isFiling"] isEqualToString:@"1"]) {
                    [MBProgressHUD showWarnMessage:@"数据已归档，不可操作！"];
                    //                    NZKAlertView *tipView = [[NZKAlertView alloc] initWithImageView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gdcg"]] title:@"数据已归档，不可重复操作" delegate:nil buttonTitle:@"我知道了"];
                    //                    [tipView show];
                    return;
                }else{
                    [self selectYueZhiPerson];
                }
            }
        }
            break;
        case 1003:
        {
            //归档
            //数据已归档不可重复操作
            //
            if ([self.selectDict allKeys].count == 0) {
                [MBProgressHUD showWarnMessage:@"请选择归档项目！"];
                return;
            }else{
                if ([self.selectDict[@"isFiling"] isEqualToString:@"1"]) {
                    NZKAlertView *tipView = [[NZKAlertView alloc] initWithImageView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gdcg"]] title:@"数据已归档，不可重复操作" delegate:nil buttonTitle:@"我知道了"];
                    [tipView show];
                    return;
                }else{
                        if(![[ValidateUtils validateNull:self.selectDict[@"toUserNum"]] isEqualToString:@"0"]){
                            [MBProgressHUD showWarnMessage:@"数据未发出阅知消息，不可归档！"];
                            return;
                        }else  if (![[ValidateUtils validateNull:self.selectDict[@"unReadNum"]] isEqualToString:[ValidateUtils validateNull:self.selectDict[@"toUserNum"]]]) {
                            [MBProgressHUD showWarnMessage:@"数据未全部读取，不可归档！"];
                            return;
                        }else{
                            [self archiveData];
                        }
                }
            }
        }
            break;
            
        default:
            break;
    }
}
#pragma mark - 归档
- (void)archiveData {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:[NSString stringWithFormat:@"%@&token=%@",yzFile,[UserInfoModel sharedInstance].token]  param:@{@"id":self.selectDict[@"id"]} completionHandler:^(id responseObject, NSError *connectionError) {
        hud.hidden = YES;
        if (!connectionError) {
            NSNumber *status = [responseObject objectForKey:@"status"];
            if (status.integerValue == 200) {
                //                [MBProgressHUD showSuccessMessage:@"归档成功！"];
                NZKAlertView *tipView = [[NZKAlertView alloc] initWithImageView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gdcg"]] title:@"归档成功" delegate:nil buttonTitle:@"我知道了"];
                [tipView show];
            }else{
                [MBProgressHUD showTipMessageInWindow:responseObject[@"message"]];
            }
        }else{
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
}

- (UIView *)backgroundAlphaView {
    if (!_backgroundAlphaView) {
        _backgroundAlphaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _backgroundAlphaView.backgroundColor = UIColor.clearColor;
        _backgroundAlphaView.userInteractionEnabled = true;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundAlphaViewTapped)];
        [_backgroundAlphaView addGestureRecognizer:tap];
    }
    return _backgroundAlphaView;
}

- (void)backgroundAlphaViewTapped {
    [self.nwglXialaImageView removeFromSuperview];
    [self.backgroundAlphaView removeFromSuperview];
    self.nwglXialaImageViewIsShowing = false;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArrayM.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YueZhiCell *cell = [tableView dequeueReusableCellWithIdentifier:yueZhiTableViewCellID];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"YueZhiCell" owner:nil options:nil]lastObject];
    }
    [cell configDict:self.dataArrayM[indexPath.row]];
    cell.xuanzhongbtnclicked = ^(BOOL selected) {
        for (NSInteger i = 0;  i < self.dataArrayM.count; i++) {
            NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.dataArrayM[i]];
            dict[@"isSelect"] = @"0";
            [self.dataArrayM replaceObjectAtIndex:i withObject:dict];
        }
        NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.dataArrayM[indexPath.row]];
        dict[@"isSelect"] = @"1";
        [self.dataArrayM replaceObjectAtIndex:indexPath.row withObject:dict];
        self.selectDict = self.dataArrayM[indexPath.row];
        [self.yueZhiTableView reloadData];
    };
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *dict = self.dataArrayM[indexPath.row];
    NSDictionary *param = @{@"token":[UserInfoModel sharedInstance].token,@"id":dict[@"id"]};
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:xxtxxqForApp param:param completionHandler:^(id responseObject, NSError *connectionError) {
        if (!connectionError) {
            NSNumber *status = [responseObject objectForKey:@"status"];
            if (status.integerValue == 200) {
                
            } else {
                [MBProgressHUD showTipMessageInWindow:[responseObject objectForKey:@"message"]];
            }
        } else {
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
    YueZhiInfoVC *yvc = [[YueZhiInfoVC alloc]init];
    yvc.type = 1;
    yvc.dict = dict;
    [self.navigationController pushViewController:yvc animated:YES];
}
- (UITableView *)yueZhiTableView {
    if (!_yueZhiTableView) {
        _yueZhiTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, headerSearchViewHeight, ScreenWidth, ScreenHeight-SafeAreaTopHeight-headerSearchViewHeight)];
        _yueZhiTableView.delegate = self;
        _yueZhiTableView.dataSource = self;
        _yueZhiTableView.backgroundColor = hexColor(F0F0F0);
        _yueZhiTableView.tableFooterView = [UIView new];
        _yueZhiTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _yueZhiTableView;
}

- (NSArray<NSDictionary *> *)selectButtonsArray {
    if (!_selectButtonsArray) {
        _selectButtonsArray = @[@{@"title":@"  新 增",@"image":@"xinzen"},
                                @{@"title":@"  编 辑",@"image":@"banli"},
                                @{@"title":@"  阅 知",@"image":@"cuiban"},
                                @{@"title":@"  归 档",@"image":@"guidang"}];
    }
    return _selectButtonsArray;
}

- (NSMutableArray *)dataArrayM {
    if (!_dataArrayM) {
        _dataArrayM = [[NSMutableArray alloc] init];
    }
    return _dataArrayM;
}

- (NSArray *)chosenArray {
    if (!_chosenArray) {
        _chosenArray = @[];
    }
    return _chosenArray;
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
